class: center, middle, inverse, title-slide # Choropleth of discrete variables --- layout: true <div class="dk-footer"> <span> <a href="https://rfortherestofus.com/" target="_blank">R for the Rest of Us </a> </span> </div> --- class: center, middle, dk-section-title background-image:url("https://images.pexels.com/photos/7138817/pexels-photo-7138817.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260") background-size: cover # Choropleth of discrete variables --- # What is a choropleth? .pull-left[ A choropleth is a shaded area map. Choropleth can communicate two types of variable: - Discrete (categorical) variables - Continuous variables ] .pull-right[ <!-- --> ] --- class: my-turn # My turn .pull-left[ I'm going to work on improving this chart in three ways: - Ordering the legend from most to least popular streaming service - Picking alternative color palettes - Specifying custom (manual) color palettes ] .pull-right[ <!-- --> ] --- ### <span style='color:#919c4c'>Geom
</span> and <span style='color:#f5c04a'>Guide
</span> order and factors We use `factors` to control the order of both geoms and guides. .pull-left[ - Default (alphabetical) ordering <img src="data:image/png;base64,#02_06_choropleth-for-discrete-variables_files/figure-html/unnamed-chunk-6-1.png" width="100%" /> ] .pull-right[ - Reordered by frequency <img src="data:image/png;base64,#02_06_choropleth-for-discrete-variables_files/figure-html/unnamed-chunk-7-1.png" width="100%" /> ] --- # `NA` values in factors `NA` is always placed at the end of a factor's levels. The only way to change this is with fct_explicit_na() .pull-left[ - Default behaviour of a factor with NA values <img src="data:image/png;base64,#02_06_choropleth-for-discrete-variables_files/figure-html/unnamed-chunk-8-1.png" width="100%" /> ] .pull-right[ ```r data %>% fct_explicit_na(vore, "Unknown")) %>% ... ``` <img src="data:image/png;base64,#02_06_choropleth-for-discrete-variables_files/figure-html/unnamed-chunk-10-1.png" width="100%" /> ] --- class: inverse ## Your turn .pull-left[ Use the `your-turn.R` script in `02_06` to make this map. - Use the custom colors. - Ensure the guide is ordered by size of region. - Add a title to the guide. ] .pull-right[ <img src="data:image/png;base64,#02_06_choropleth-for-discrete-variables_files/figure-html/unnamed-chunk-11-1.png" width="100%" /> ]